<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>名师精品课</title>
<link href="../c/base.css" rel="stylesheet" type="text/css">
<link href="../c/toefl.css" rel="stylesheet" type="text/css">
<link href="../c/bootstrap.min.css" rel="stylesheet" type="text/css">
<script src="../j/jquery-2.1.0.js" type="text/javascript"
	charset="utf-8"></script>
<script src="../j/bootstrap.min.js" type="text/javascript"
	charset="utf-8"></script>
<script src="../layer/layer.js" type="text/javascript" charset="utf-8"></script>	
<style>
.nowPage {
	color: red;
}
</style>
</head>

<script type="text/javascript">
	function searchCastle(pageNum, mallType) {
		
		$("#pageNum").attr("value", pageNum);
		$("#mallType").attr("value", mallType);
		$("#searchCastle").submit();
	}
	
	function getAttas(castle_id){
		$.ajax({
			url:'getAttas',
			dataType:'json',
			type:'post',
			data:{
				castle_id:castle_id
			},
			success:function(result){
				var html = "";
				for(var i = 0; i < result.length; i++){
					html += "<li><span class='flcb_cardDownloadZl'>资料"
						+ (i+1) + 
						"</span><span class='flcb_cardDownloadBt'>" 
						+ result[i].attachment_name + 
						"</span><a href='downloadAtta?attachment_id="
						+ result[i].attachment_id +
						"' class='flcb_cardDownloadXz'>&nbsp;</a></li>";
					}
				$("#lili").html(html);
			}
		})
		
	}
	function phrase(teacher_id){
		var isPhrase = $("#isPhrase_" + teacher_id);
		var loginMessage = $("#loginMessage").val();
		var flag;
		if(isPhrase.text() == '赞'){
			flag = 1;
		}else if (isPhrase.text() == '取消'){
			flag = 2;
		}
		if (loginMessage == null || loginMessage == '') {
			layer.confirm('请先登录，再点赞！！', {
				title : '提示'
			}, function(index) {
				window.parent.location = "toLogin";
				layer.close(index);
			}, function() {
				layer.close();
			});

		} else if (loginMessage == 'teacher') {
			layer.confirm('只有用户才可以点赞，请使用用户账号登录！！', {
				title : '提示'
			}, function(index) {
				window.parent.location = "toLogin";
				layer.close(index);
			}, function() {
				layer.close();
			});
		} else {
			$.ajax({
				url : 'addOrDelPhrase',
				type : 'post',
				dataType : 'json',
				data : {
					teacher_id : teacher_id,
					flag : flag
				},
				success : function(result){
					if(result != null){
						$("#searchCastle").submit();
					}
				}
				
			})
		}
		
	}
</script>

<body>
	<input type="hidden" name="loginMessage" id="loginMessage"
		th:value="${session.loginMessage}">
	<form action="toMyCastle" method="post" id="searchCastle">
		<input type="hidden" id="mallType" name="mall_type"
			th:value="${castleInfo.mall_type}"> <input type="hidden"
			id="pageNum" name="pageNum" th:value="${castleInfo.pageNum}">
	</form>
	<div class="doc910">
		<div class="flcb_cardMenu" style="position: relative;">
			<ul>
				<li th:if="${session.loginMessage == 'user'}"
					th:class="${castleInfo.mall_type == 1}?on:''"><a href="###"
					id="gongyi" onclick="searchCastle(1,1)">公益活动</a></li>
				<li th:if="${session.loginMessage == 'user'}"
					th:class="${castleInfo.mall_type == 2}?on:''"><a href="###"
					id="tese" onclick="searchCastle(1,2)">特色活动</a></li>
				<li th:if="${session.loginMessage == 'user'}"
					th:class="${castleInfo.mall_type == 3}?on:''"><a href="###"
					id="mingshi" onclick="searchCastle(1,3)">名师精品课</a></li>
				<li th:if="${session.loginMessage == 'teacher'}" class="on"><a
					href="###" id='wode'>我的发布</a></li>
			</ul>
			<div style="position: absolute; right: 10px;"
				th:if="${session.loginMessage == 'teacher'}">
				<button type="button" class="btn btn-success "
					onclick="window.location.href='toCastlePublish'">
					<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
					发布
				</button>
			</div>
		</div>
		<div class="flcb_cardMain" id="gongyiContent"
			th:if="${session.loginMessage == 'user'}">
			<dl th:each="castle:${pageInfo.list}" th:object="${castle.castleInfo}">
				<dt>
					<a href="#"><img th:src="*{img_url}" width="270"
						height="155"></a>
				</dt>
				<dd>
					<div class="flcb_cardClass">
						<h3>[[*{class_title}]]</h3>
						<div class="flcb_cardNum">
							<span>[[*{signup_num}]]</span>人购买
						</div>
					</div>
					<div class="castleTime">
						上课时间：<span>[[*{#dates.format(start_date,
							'yyyy-MM-dd')}]]</span>到<span>[[*{#dates.format(end_date,
							'yyyy-MM-dd')}]]</span>&nbsp;&nbsp;&nbsp;&nbsp; 每周： <span
							style="color: green;">[[*{castle_cycle}]]</span>&nbsp;的&nbsp;<span
							style="color: red;">[[*{#dates.format(start_time,
							'HH: mm')}]]-[[*{#dates.format(end_time, 'HH: mm')}]]</span>上课
					</div>

					<div class="castleTech">
						<span class="first">主讲老师：</span> <span class="teacherPic"><img
							th:src="*{teacher.img_url}"></span> <span class="name">[[*{teacher.user_name}]]</span>
						<span class="zan"><a href="###"
								th:onclick="phrase([[*{teacher_id}]])"><img
									src="../i/icon_zan14x14.jpg"></a></span>
							<div th:switch="*{teacher_id}"
								th:if="${session.loginMessage == 'user'}">
								<div th:each="phrase : ${teacherPhrases}">
									<span class="zan" th:case="${phrase.teacher_id}"
										th:id="'isPhrase_' + *{teacher_id}" style="width:40px">取消</span>
								</div>
								<span class="zan" th:case="*"
									th:id="'isPhrase_' + *{teacher_id}" style="width:40px">赞</span>
							</div>
							<span class="zan"
								th:if="${session.loginMessage == 'teacher' || session.loginMessage == null}"
								th:id="'isPhrase_' + *{teacher_id}">赞</span><span
								class="zanNum">（[[*{teacher.phrase_num}]]）</span>

					</div>
					<div class="flcb_cardButton">
						<a th:href="@{/toCastleDetail(castle_id=*{castle_id})}">活动详情</a>
						<a th:href="@{/delSignup(castle_id=*{castle_id})}"
							onclick="return confirm('你确定要退出吗？');">我要退出</a> <a href="###"
							data-toggle="modal" data-target=".modal" th:onclick="getAttas([[*{castle_id}]])">资料下载</a>
					</div>
				</dd>
			</dl>
		</div>
		<div class="flcb_cardMain" id="wodeContent"
			th:if="${session.loginMessage == 'teacher'}">
			<dl th:each="castle:${pageInfo.list}">
				<dt>
					<a href="#"><img th:src="${castle.img_url}" width="270"
						height="155"></a>
				</dt>
				<dd>
					<div class="flcb_cardClass">
						<h3>[[${castle.class_title}]]</h3>
						<div class="flcb_cardNum">
							<span>[[${castle.signup_num}]]</span>人购买
						</div>
					</div>
					<div class="castleTime">
						上课时间：<span>[[${#dates.format(castle.start_date,
							'yyyy-MM-dd')}]]</span>到<span>[[${#dates.format(castle.end_date,
							'yyyy-MM-dd')}]]</span>&nbsp;&nbsp;&nbsp;&nbsp; 每周： <span
							style="color: green;">[[${castle.castle_cycle}]]</span>&nbsp;的&nbsp;<span
							style="color: red;">[[${#dates.format(castle.start_time,
							'HH: mm')}]]-[[${#dates.format(castle.end_time, 'HH: mm')}]]</span>上课
					</div>

					<div class="castleTech">
						<span class="first">主讲老师：</span> <span class="teacherPic"><img
							th:src="${castle.teacher.img_url}"></span> <span class="name">[[${castle.teacher.user_name}]]</span>
						<span class="zan"><a href="###"
								th:onclick="phrase([[${castle.teacher_id}]])"><img
									src="../i/icon_zan14x14.jpg"></a></span>
							<span class="zan"
								th:if="${session.loginMessage == 'teacher' || session.loginMessage == null}"
								th:id="'isPhrase_' + ${castle.teacher_id}">赞</span><span
								class="zanNum">（[[${castle.teacher.phrase_num}]]）</span>

					</div>
					<div class="flcb_cardButton">
						<a th:href="@{/toCastleDetail(castle_id=${castle.castle_id})}">活动详情</a>
						<a th:href="@{/toCastlePublish(castle_id=${castle.castle_id})}">编辑</a>
						<a th:href="@{/delCastle(castle_id=${castle.castle_id})}"
							onclick="return confirm('你确定要删除吗？');">删除</a>
					</div>
				</dd>
			</dl>
		</div>
		<div class="pageList">
			<ul th:if="${pageInfo.pages != 0}">
				<li th:if="${pageInfo.pageNum != 1}"><a href="###"
					th:onclick="searchCastle(1)">首页</a></li>
				<li th:each="pages:${pageInfo.navigatepageNums}"><a href="###"
					th:class="${pages == pageInfo.pageNum} ? nowPage : ''"
					th:onclick="searchCastle([[${pages}]])">【[[${pages}]]】</a></li>
				<li th:if="${pageInfo.pageNum != pageInfo.pages}"><a href="###"
					th:onclick="searchCastle([[${pageInfo.pages}]])">最后一页</a></li>
				<li th:if="${pageInfo.pageNum != 1}"><a href="###" class="pret"
					th:onclick="searchCastle([[${pageInfo.prePage}]])">上一页</a></li>
				<li th:if="${pageInfo.pageNum != pageInfo.pages}"><a href="###"
					class="next" th:onclick="searchCastle([[${pageInfo.nextPage}]])">下一页</a></li>
			</ul>
		</div>
	</div>
	<div class="modal fade" tabindex="-1" role="dialog">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">课程资料</h4>
				</div>
				<div class="modal-body">
					<div class="flcb_cardDownload">
						<h3 class="flcb_cardDownloadT">课程资料下载</h3>
						<ul id="lili">
							
						</ul>

					</div>

				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
</body>
</html>
